package logic

import (
	"context"
	"net/http"
	"project/weeksrv/weeksrv"

	"project/client/internal/svc"
	"project/client/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetEsSearchSortByPriceSalesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetEsSearchSortByPriceSalesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEsSearchSortByPriceSalesLogic {
	return &GetEsSearchSortByPriceSalesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetEsSearchSortByPriceSalesLogic) GetEsSearchSortByPriceSales(req *types.GetEsSearchSortByPriceSalesReq) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.WeekSrv.GetEsSearchSortByPriceSales(l.ctx, &weeksrv.GetEsSearchSortByPriceSalesReq{SortId: req.SortId})
	if err != nil {
		return &types.Response{
			Code:    http.StatusUnauthorized,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    http.StatusOK,
		Message: "search successfully",
		Data: map[string]interface{}{
			"data": res.Goods,
		},
	}, nil
}
